<?php

require_once('Zabbix.php');

/**
 *
 */
class Zabbix_Sensor_Mysql extends Zabbix_Sensor {

    protected $_attributes = array();

    /**
     *
     */
    public function init() {

        $host = $this->getOption('host', '127.0.0.1');
        $user = $this->getOption('root', 'root');
        $passwd = $this->getOption('root', '');

        $link = mysql_connect($host, $user, $passwd) or die(mysql_error());
        $query = 'SHOW STATUS';
        $result = mysql_query($query) or die(mysql_error());
        while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $name  = $line['Variable_name'];
            $value = $line['Value'];

            $this->setAttribute($name, $value);
        }
        mysql_free_result($result);
        mysql_close($link);
    }

    public function setAttribute($name, $value) {
        $this->_attributes[$name] = $value;
    }

    public function getAttribute($name) {
        $result = null;
        if (array_key_exists($name, $this->_attributes)) {
            $result = $this->_attributes[$name];
        }
        return $result;
    }

    /**
     */
    public function getAttributes() {
        return $this->_attributes;
    }


}
